package com.woniuxy;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.vo.Address;
import com.woniuxy.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@SpringBootApplication
@Controller
//指定mapper文件包路径
//@MapperScan(basePackages = "com.woniuxy")
public class MybatisPlusDemoMain {
    public static void main(String[] args) {
        SpringApplication.run(MybatisPlusDemoMain.class);
    }

    @Autowired
    UserMapper userMapper;

    @RequestMapping("/")
    @ResponseBody
    public List<User> allUser(){
//        List<User> users = userMapper.queryAllUser();

        //QueryWrapper组装查询条件
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",1);
        User user = userMapper.selectOne(queryWrapper);
        System.out.println(user);

        List<User> queryAllUserIdBigThan2 = userMapper.queryAllUserIdBigThan2();


        //不指定查询条件,那就查询所有数据
        List<User> users = userMapper.selectList(null);

        return users;
    }

    @Autowired
    AddressMapper addressMapper;

    @Autowired
    AddressService addressService;

    @RequestMapping("/address")
    @ResponseBody
    public List<Address> allAddress(){

        //直接调用mapper查数据
//        List<Address> addresses = addressMapper.selectList(null);
//        return addresses;

        //用Service查数据
        List<Address> addressList = addressService.list();
        return addressList;
    }


}